package JmmAndMultiThread;

import java.util.logging.Logger;

public class JmmVolatileVisibility {
    static Logger logger=Logger.getLogger(String.valueOf(JmmVolatileVisibility.class));
    private static  boolean innitFlag=false;
    public static  void refresh(){
        logger.info("refreshing innitFlag……");
        innitFlag=true;
        logger.info("innitFlag was refreshed……");
    }
    public static  void loadData(){
        logger.info("Start loading……");
        while (!innitFlag){
        }
    }

    public static void main(String[] args) {
        Thread threadA = new Thread(()->{
            loadData();
        },"threadA");
        threadA.start();
        try {
            Thread.sleep(500);
            logger.info(Thread.currentThread().getName()+" sleep for 500 ms");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Thread threadB = new Thread(()->{
            refresh();
        },"threadB");
        threadB.start();

    }
}
